package aes.gui;

import java.awt.CardLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import aes.general.AdminControl;
import javax.swing.ScrollPaneConstants;

/**
 * The Class AdminViewQuestionsPanel. This panel shows questions to the admin.
 */
public class AdminViewQuestionsPanel extends JPanel {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;
	private JPanel jp;
	private JTable table;
	private JLabel lblQuestions;
	private JSeparator separator;
	private JButton b1;
	
	private DefaultTableModel model;
	private ArrayList<String> questions = new ArrayList<String>();
	
	/**
	 * Create the panel.
	 * 
	 * @param contentPane
	 *            the content pane
	 */
	public AdminViewQuestionsPanel(JPanel contentPane) {
		this.jp = contentPane;
		setLayout(null);
		initialize();
	}

	
	/**
	 * Initialize.
	 */
	private void initialize() {
		lblQuestions = new JLabel("Questions");
		lblQuestions.setFont(new Font("Tempus Sans ITC", Font.BOLD, 21));
		lblQuestions.setBounds(255, 11, 129, 29);
		add(lblQuestions);
		
		separator = new JSeparator();
		separator.setBounds(10, 43, 620, 2);
		add(separator);
		
		try {
			Thread.sleep(500);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}
		questions = AdminControl.getQuestions();
		
		String col[] = {"ExamId","Teacher ID","Subject", "Question"};
		String data[][] = {{}};
		model = new DefaultTableModel(data,col);
		
		int j = 0;
		for(int i=0;i<questions.size();i++,j++)
			model.insertRow(j,new Object[]{questions.get(i),questions.get(++i),questions.get(++i),questions.get(++i)});
		model.removeRow(j);
		b1 = new JButton("Back");
		b1.setBounds(268, 402, 91, 23);
		add(b1);
		
		JPanel panel = new JPanel();
		panel.setBounds(20, 56, 610, 330);
		add(panel);
		panel.setLayout(null);
		
		table = new JTable(model);
		table.setFont(new Font("Tahoma", Font.BOLD, 12));
		table.setBounds(26, 90, 575, 284);
		JScrollPane sc = new JScrollPane(table);
		sc.setBounds(10, 5, 573, 314);
		panel.add(sc);
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				questions.clear();
				CardLayout cl = (CardLayout) (jp.getLayout());
				cl.show(jp, "AdminMain");	
			}
		});
	}
}
